package cn.summit;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author summit
 * @since 2022/1/16 21:20
 */
@RestController
@RequestMapping("/order")
@Slf4j
@RefreshScope
public class TestController {
	@Autowired
	private RestTemplate restTemplate;

	/**
	 * nacos服务注册发现
	 */
	@GetMapping("/shop")
	public String shop() {
		String forObject = restTemplate.getForObject("http://stock-server/jian", String.class);
		log.info("返回信息:{}", forObject);
		return "订单成功";
	}

	@Value("${summit.name}")
	private String name;

	/**
	 * nacos-config 测试
	 */
	@GetMapping("/config")
	public String getConfig() {
		return name;
	}

	@Value("${summit.ip}")
	private String ip;

	@GetMapping("/ip")
	public String getIp() {
		log.info("ip===>{}", ip);
		return ip;
	}
}
